// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

namespace SnapObjects.Commons
{
    public class TrackLogger
    {
        public static void ExcuteSqlLog(IDbCommand command)
        {
            Trace.WriteLine("---------------------------------------");
            Trace.WriteLine($"Thread ID: {Thread.CurrentThread.ManagedThreadId}");
            Trace.WriteLine("SQL:");
            Trace.WriteLine(command.CommandText);

            foreach (IDbDataParameter parameter in command.Parameters)
            {
                var value = parameter.Value;

                if (value is DateTime dt)
                {
                    value = dt.ToString("yyyy-MM-dd HH:mm:ss.FFFFFF", CultureInfo.InvariantCulture);
                }

                Trace.WriteLine($"{parameter.ParameterName} = {value}");
            }
        }

        public static void LogInformation(string message)
        {
            Trace.WriteLine(message);
        }
    }
}
